library("FRESA.CAD")
library(readxl)
library(igraph)
library(umap)
library(tsne)
library(entropy)
op <- par(no.readonly = TRUE)
pander::panderOptions('digits', 3)
pander::panderOptions('table.split.table', 400)
pander::panderOptions('keep.trailing.zeros',TRUE)
The data to process is described in:
https://zenodo.org/record/4156647#.Y1bSF3bMKUk
IR Saliva Testing Dataset
10.5281/zenodo.4156647 https://doi.org/10.5281/zenodo.4156647
I added a column to the data identifying the repeated experiments.
SalivaIR <- as.data.frame(read_excel("~/GitHub/FCA/Data/SalivaThermal_Source_Data_2.xlsx"))
SalivaIR_set1 <- subset(SalivaIR,RepID==1)
rownames(SalivaIR_set1) <- SalivaIR_set1$ID
SalivaIR_set1$RepID <- NULL
SalivaIR_set1$ID <- NULL
SalivaIR_set1$Ct <- NULL
SalivaIR_set2 <- subset(SalivaIR,RepID==2)
rownames(SalivaIR_set2) <- SalivaIR_set2$ID
SalivaIR_set2$RepID <- NULL
SalivaIR_set2$ID <- NULL
SalivaIR_set2$Ct <- NULL
SalivaIR_set3 <- subset(SalivaIR,RepID==3)
rownames(SalivaIR_set3) <- SalivaIR_set3$ID
SalivaIR_set3$RepID <- NULL
SalivaIR_set3$ID <- NULL
SalivaIR_set3$Ct <- NULL
SalivaIR_Avg <- (SalivaIR_set1 + SalivaIR_set2 + SalivaIR_set3)/3
colnames(SalivaIR_Avg) <- paste("V",colnames(SalivaIR_Avg),sep="_")
SalivaIR_Avg$class <- 1*(str_detect(rownames(SalivaIR_Avg),"P"))
pander::pander(table(SalivaIR_Avg$class))
| 0 | 1 |
|---|---|
| 30 | 31 |
studyName <- "IRSaliva"
dataframe <- SalivaIR_Avg
outcome <- "class"
TopVariables <- 10
thro <- 0.80
cexheat = 0.15
Some libraries
library(psych)
library(whitening)
library("vioplot")
library("rpart")
pander::pander(c(rows=nrow(dataframe),col=ncol(dataframe)-1))
| rows | col |
|---|---|
| 61 | 251 |
pander::pander(table(dataframe[,outcome]))
| 0 | 1 |
|---|---|
| 30 | 31 |
varlist <- colnames(dataframe)
varlist <- varlist[varlist != outcome]
largeSet <- length(varlist) > 1500
Scaling and removing near zero variance columns and highly co-linear(r>0.99999) columns
### Some global cleaning
sdiszero <- apply(dataframe,2,sd) > 1.0e-16
dataframe <- dataframe[,sdiszero]
varlist <- colnames(dataframe)[colnames(dataframe) != outcome]
tokeep <- c(as.character(correlated_Remove(dataframe,varlist,thr=0.99999)),outcome)
dataframe <- dataframe[,tokeep]
varlist <- colnames(dataframe)
varlist <- varlist[varlist != outcome]
iscontinous <- sapply(apply(dataframe,2,unique),length) >= 5 ## Only variables with enough samples
dataframeScaled <- FRESAScale(dataframe,method="OrderLogit")$scaledData
numsub <- nrow(dataframe)
if (numsub > 1000) numsub <- 1000
if (!largeSet)
{
hm <- heatMaps(data=dataframeScaled[1:numsub,],
Outcome=outcome,
Scale=TRUE,
hCluster = "row",
xlab="Feature",
ylab="Sample",
srtCol=45,
srtRow=45,
cexCol=cexheat,
cexRow=cexheat
)
par(op)
}
The heat map of the data
if (!largeSet)
{
par(cex=0.6,cex.main=0.85,cex.axis=0.7)
#cormat <- Rfast::cora(as.matrix(dataframe[,varlist]),large=TRUE)
cormat <- cor(dataframe[,varlist],method="pearson")
cormat[is.na(cormat)] <- 0
gplots::heatmap.2(abs(cormat),
trace = "none",
# scale = "row",
mar = c(5,5),
col=rev(heat.colors(5)),
main = "Original Correlation",
cexRow = cexheat,
cexCol = cexheat,
srtCol=45,
srtRow=45,
key.title=NA,
key.xlab="|Pearson Correlation|",
xlab="Feature", ylab="Feature")
diag(cormat) <- 0
print(max(abs(cormat)))
}
[1]
0.999994
DEdataframe <- IDeA(dataframe,verbose=TRUE,thr=thro)
#>
#> V_1138
#> V_1300 V_1298 V_1296 V_1294 V_1292 V_1290
#> 0.03571429 0.04017857 0.05357143 0.05803571 0.06250000 0.06696429
#>
#> Included: 224 , Uni p: 0.0006696429 , Base Size: 1 , Rcrit: 0.4015439
#>
#>
1 <R=1.000,thr=0.950>, Top: 1< 223 >[Fa= 1 ]( 1 , 223 , 0 ),<|><>Tot Used: 224 , Added: 223 , Zero Std: 0 , Max Cor: 1.000
#>
2 <R=1.000,thr=0.950>, Top: 4< 20 >[Fa= 5 ]( 4 , 40 , 1 ),<|><>Tot Used: 224 , Added: 40 , Zero Std: 0 , Max Cor: 1.000
#>
3 <R=1.000,thr=0.950>, Top: 11< 20 >[Fa= 16 ]( 11 , 67 , 5 ),<|><>Tot Used: 224 , Added: 67 , Zero Std: 0 , Max Cor: 1.000
#>
4 <R=1.000,thr=0.950>, Top: 20< 3 >[Fa= 36 ]( 20 , 52 , 16 ),<|><>Tot Used: 224 , Added: 52 , Zero Std: 0 , Max Cor: 1.000
#>
5 <R=1.000,thr=0.950>, Top: 19< 19 >[Fa= 55 ]( 19 , 68 , 36 ),<|><>Tot Used: 224 , Added: 68 , Zero Std: 0 , Max Cor: 1.000
#>
6 <R=1.000,thr=0.950>, Top: 20< 28 >[Fa= 75 ]( 20 , 91 , 55 ),<|><>Tot Used: 224 , Added: 91 , Zero Std: 0 , Max Cor: 0.999
#>
7 <R=0.999,thr=0.950>, Top: 22< 5 >[Fa= 97 ]( 22 , 55 , 75 ),<|><>Tot Used: 224 , Added: 55 , Zero Std: 0 , Max Cor: 0.999
#>
8 <R=0.999,thr=0.950>, Top: 19< 3 >[Fa= 116 ]( 19 , 36 , 97 ),<|><>Tot Used: 224 , Added: 36 , Zero Std: 0 , Max Cor: 0.998
#>
9 <R=0.998,thr=0.950>, Top: 11< 2 >[Fa= 127 ]( 11 , 18 , 116 ),<|><>Tot Used: 224 , Added: 18 , Zero Std: 0 , Max Cor: 0.998
#>
10 <R=0.998,thr=0.950>, Top: 8< 1 >[Fa= 135 ]( 8 , 10 , 127 ),<|><>Tot Used: 224 , Added: 10 , Zero Std: 0 , Max Cor: 0.988
#>
11 <R=0.988,thr=0.950>, Top: 1< 1 >[Fa= 136 ]( 1 , 1 , 135 ),<|><>Tot Used: 224 , Added: 1 , Zero Std: 0 , Max Cor: 0.950
#>
12 <R=0.950,thr=0.900>, Top: 49< 1 >[Fa= 138 ]( 49 , 54 , 136 ),<|><>Tot Used: 224 , Added: 54 , Zero Std: 0 , Max Cor: 0.997
#>
13 <R=0.997,thr=0.950>, Top: 30< 1 >[Fa= 147 ]( 30 , 31 , 138 ),<|><>Tot Used: 224 , Added: 31 , Zero Std: 0 , Max Cor: 0.995
#>
14 <R=0.995,thr=0.950>, Top: 12< 1 >[Fa= 151 ]( 12 , 12 , 147 ),<|><>Tot Used: 224 , Added: 12 , Zero Std: 0 , Max Cor: 0.996
#>
15 <R=0.996,thr=0.950>, Top: 2< 1 >[Fa= 151 ]( 2 , 2 , 151 ),<|><>Tot Used: 224 , Added: 2 , Zero Std: 0 , Max Cor: 0.950
#>
16 <R=0.950,thr=0.900>, Top: 19< 1 >[Fa= 151 ]( 18 , 19 , 151 ),<|><>Tot Used: 224 , Added: 19 , Zero Std: 0 , Max Cor: 0.998
#>
17 <R=0.998,thr=0.950>, Top: 9< 1 >[Fa= 153 ]( 9 , 9 , 151 ),<|><>Tot Used: 224 , Added: 9 , Zero Std: 0 , Max Cor: 0.994
#>
18 <R=0.994,thr=0.950>, Top: 3< 1 >[Fa= 154 ]( 3 , 3 , 153 ),<|><>Tot Used: 224 , Added: 3 , Zero Std: 0 , Max Cor: 0.949
#>
19 <R=0.949,thr=0.900>, Top: 10< 1 >[Fa= 154 ]( 10 , 10 , 154 ),<|><>Tot Used: 224 , Added: 10 , Zero Std: 0 , Max Cor: 0.997
#>
20 <R=0.997,thr=0.950>, Top: 4< 1 >[Fa= 154 ]( 4 , 4 , 154 ),<|><>Tot Used: 224 , Added: 4 , Zero Std: 0 , Max Cor: 0.986
#>
21 <R=0.986,thr=0.950>, Top: 1< 1 >[Fa= 155 ]( 1 , 1 , 154 ),<|><>Tot Used: 224 , Added: 1 , Zero Std: 0 , Max Cor: 0.914
#>
22 <R=0.914,thr=0.900>, Top: 1< 1 >[Fa= 156 ]( 1 , 1 , 155 ),<|><>Tot Used: 224 , Added: 1 , Zero Std: 0 , Max Cor: 0.900
#>
23 <R=0.900,thr=0.800>, Top: 36< 3 >[Fa= 157 ]( 32 , 40 , 156 ),<|><>Tot Used: 224 , Added: 40 , Zero Std: 0 , Max Cor: 0.983
#>
24 <R=0.983,thr=0.950>, Top: 6< 1 >[Fa= 157 ]( 6 , 6 , 157 ),<|><>Tot Used: 224 , Added: 6 , Zero Std: 0 , Max Cor: 0.975
#>
25 <R=0.975,thr=0.950>, Top: 3< 1 >[Fa= 158 ]( 3 , 3 , 157 ),<|><>Tot Used: 224 , Added: 3 , Zero Std: 0 , Max Cor: 0.938
#>
26 <R=0.938,thr=0.900>, Top: 1< 1 >[Fa= 158 ]( 1 , 1 , 158 ),<|><>Tot Used: 224 , Added: 1 , Zero Std: 0 , Max Cor: 0.888
#>
27 <R=0.888,thr=0.800>, Top: 20< 1 >[Fa= 159 ]( 19 , 20 , 158 ),<|><>Tot Used: 224 , Added: 20 , Zero Std: 0 , Max Cor: 0.953
#>
28 <R=0.953,thr=0.950>, Top: 2< 1 >[Fa= 160 ]( 2 , 2 , 159 ),<|><>Tot Used: 224 , Added: 2 , Zero Std: 0 , Max Cor: 0.991
#>
29 <R=0.991,thr=0.950>, Top: 1< 1 >[Fa= 160 ]( 1 , 1 , 160 ),<|><>Tot Used: 224 , Added: 1 , Zero Std: 0 , Max Cor: 0.922
#>
30 <R=0.922,thr=0.900>, Top: 3< 1 >[Fa= 160 ]( 3 , 3 , 160 ),<|><>Tot Used: 224 , Added: 3 , Zero Std: 0 , Max Cor: 0.926
#>
31 <R=0.926,thr=0.900>, Top: 1< 1 >[Fa= 160 ]( 1 , 1 , 160 ),<|><>Tot Used: 224 , Added: 1 , Zero Std: 0 , Max Cor: 0.910
#>
32 <R=0.910,thr=0.900>, Top: 1< 1 >[Fa= 160 ]( 1 , 1 , 160 ),<|><>Tot Used: 224 , Added: 1 , Zero Std: 0 , Max Cor: 0.885
#>
33 <R=0.885,thr=0.800>, Top: 7< 1 >[Fa= 162 ]( 7 , 7 , 160 ),<|><>Tot Used: 224 , Added: 7 , Zero Std: 0 , Max Cor: 0.910
#>
34 <R=0.910,thr=0.900>, Top: 1< 1 >[Fa= 162 ]( 1 , 1 , 162 ),<|><>Tot Used: 224 , Added: 1 , Zero Std: 0 , Max Cor: 0.799
#>
35 <R=0.799,thr=0.800>
#>
[ 35 ], 0.7992318 Decor Dimension: 224 Nused: 224 . Cor to Base: 223 , ABase: 224 , Outcome Base: 0
#>
varlistc <- colnames(DEdataframe)[colnames(DEdataframe) != outcome]
pander::pander(sum(apply(dataframe[,varlist],2,var)))
5.5
pander::pander(sum(apply(DEdataframe[,varlistc],2,var)))
0.036
pander::pander(entropy(discretize(unlist(dataframe[,varlist]), 256)))
5.08
pander::pander(entropy(discretize(unlist(DEdataframe[,varlistc]), 256)))
0.886
varratio <- attr(DEdataframe,"VarRatio")
pander::pander(tail(varratio))
| La_V_1124 | La_V_856 | La_V_964 | La_V_996 | La_V_1134 | La_V_1236 |
|---|---|---|---|---|---|
| 9.48e-10 | 8.77e-10 | 5.99e-10 | 4.91e-10 | 3.91e-10 | 3.41e-10 |
if (!largeSet)
{
par(cex=0.6,cex.main=0.85,cex.axis=0.7)
UPLTM <- attr(DEdataframe,"UPLTM")
gplots::heatmap.2(1.0*(abs(UPLTM)>0),
trace = "none",
mar = c(5,5),
col=rev(heat.colors(5)),
main = "Decorrelation matrix",
cexRow = cexheat,
cexCol = cexheat,
srtCol=45,
srtRow=45,
key.title=NA,
key.xlab="|Beta|>0",
xlab="Output Feature", ylab="Input Feature")
par(op)
}
Displaying the features associations
par(op)
clustable <- c("To many variables")
transform <- attr(DEdataframe,"UPLTM") != 0
tnames <- colnames(transform)
colnames(transform) <- str_remove_all(colnames(transform),"La_")
transform <- abs(transform*cor(dataframe[,rownames(transform)])) # The weights are proportional to the observed correlation
fscore <- attr(DEdataframe,"fscore")
VertexSize <- fscore # The size depends on the variable independence relevance (fscore)
names(VertexSize) <- str_remove_all(names(VertexSize),"La_")
VertexSize <- 10*(VertexSize-min(VertexSize))/(max(VertexSize)-min(VertexSize)) # Normalization
VertexSize <- VertexSize[rownames(transform)]
rsum <- apply(1*(transform !=0),1,sum) + 0.01*VertexSize + 0.001*varratio[tnames]
csum <- apply(1*(transform !=0),2,sum) + 0.01*VertexSize + 0.001*varratio[tnames]
ntop <- min(10,length(rsum))
topfeatures <- unique(c(names(rsum[order(-rsum)])[1:ntop],names(csum[order(-csum)])[1:ntop]))
rtrans <- transform[topfeatures,]
csum <- (apply(1*(rtrans !=0),2,sum) > 1*(colnames(rtrans) %in% topfeatures))
rtrans <- rtrans[,csum]
topfeatures <- unique(c(topfeatures,colnames(rtrans)))
print(ncol(transform))
[1] 224
transform <- transform[topfeatures,topfeatures]
print(ncol(transform))
[1] 224
if (ncol(transform)>100)
{
csum <- apply(1*(transform !=0),1,sum)
csum <- csum[csum > 1]
csum <- csum + 0.01*VertexSize[names(csum)]
csum <- csum[order(-csum)]
tpsum <- min(20,length(csum))
trsum <- rownames(transform)[rownames(transform) %in% names(csum[1:tpsum])]
rtrans <- transform[trsum,]
topfeatures <- unique(c(rownames(rtrans),colnames(rtrans)))
transform <- transform[topfeatures,topfeatures]
if (nrow(transform) > 150)
{
csum <- apply(1*(rtrans != 0 ),2,sum)
csum <- csum + 0.01*VertexSize[names(csum)]
csum <- csum[order(-csum)]
tpsum <- min(130,length(csum))
csum <- rownames(transform)[rownames(transform) %in% names(csum[1:tpsum])]
csum <- unique(c(trsum,csum))
transform <- transform[csum,csum]
}
print(ncol(transform))
}
[1] 131
if (ncol(transform) < 150)
{
gplots::heatmap.2(transform,
trace = "none",
mar = c(5,5),
col=rev(heat.colors(5)),
main = "Red Decorrelation matrix",
cexRow = cexheat,
cexCol = cexheat,
srtCol=45,
srtRow=45,
key.title=NA,
key.xlab="|Beta|>0",
xlab="Output Feature", ylab="Input Feature")
par(op)
VertexSize <- VertexSize[colnames(transform)]
gr <- graph_from_adjacency_matrix(transform,mode = "directed",diag = FALSE,weighted=TRUE)
gr$layout <- layout_with_fr
fc <- cluster_optimal(gr)
plot(fc, gr,
edge.width = 2*E(gr)$weight,
vertex.size=VertexSize,
edge.arrow.size=0.5,
edge.arrow.width=0.5,
vertex.label.cex=(0.15+0.05*VertexSize),
vertex.label.dist=0.5 + 0.05*VertexSize,
main="Top Feature Association")
varratios <- varratio
fscores <- fscore
names(varratios) <- str_remove_all(names(varratios),"La_")
names(fscores) <- str_remove_all(names(fscores),"La_")
dc <- getLatentCoefficients(DEdataframe)
theCharformulas <- attr(dc,"LatentCharFormulas")
clustable <- as.data.frame(cbind(Variable=fc$names,
Formula=as.character(theCharformulas[paste("La_",fc$names,sep="")]),
Class=fc$membership,
ResidualVariance=round(varratios[fc$names],3),
Fscore=round(fscores[fc$names],3)
)
)
rownames(clustable) <- str_replace_all(rownames(clustable),"__","_")
clustable$Variable <- NULL
clustable$Class <- as.integer(clustable$Class)
clustable$ResidualVariance <- as.numeric(clustable$ResidualVariance)
clustable$Fscore <- as.numeric(clustable$Fscore)
clustable <- clustable[order(-clustable$Fscore),]
clustable <- clustable[order(clustable$Class),]
clustable <- clustable[clustable$Fscore >= -1,]
topv <- min(50,nrow(clustable))
clustable <- clustable[1:topv,]
}
pander::pander(clustable)
| Formula | Class | ResidualVariance | Fscore | |
|---|---|---|---|---|
| V_1138 | NA | 1 | 1.000 | 223 |
| V_1114 | - (0.962)V_1138 + V_1114 - (9.632)V_972 + (9.553)V_970 | 1 | 0.002 | 8 |
| V_1102 | + (3.77e-03)V_1138 + (3.844)V_1114 - (4.856)V_1112 + V_1102 | 1 | 0.000 | 3 |
| V_1112 | + (0.077)V_1138 - (1.074)V_1114 + V_1112 | 1 | 0.000 | 2 |
| V_1090 | - (0.110)V_1138 + (0.328)V_1114 - (1.272)V_1094 + (1.700)V_1090 - (0.651)V_1086 | 1 | 0.000 | 2 |
| V_1110 | - (6.52e-03)V_1138 + (0.776)V_1114 - (1.699)V_1112 + V_1110 - (0.070)V_1102 | 1 | 0.000 | 0 |
| V_1094 | + (0.525)V_1138 - (1.532)V_1114 + V_1094 | 1 | 0.001 | 0 |
| V_956 | - (0.316)V_1138 + (16.639)V_1026 - (17.256)V_1024 + V_956 | 2 | 0.018 | 27 |
| V_954 | + (0.012)V_1138 - (1.010)V_956 + V_954 | 2 | 0.000 | 8 |
| V_902 | + (0.042)V_1138 - (0.318)V_956 + V_902 - (0.712)V_894 | 2 | 0.001 | 3 |
| V_934 | + (8.69e-03)V_1138 - (0.887)V_956 + (1.148)V_954 - (1.274)V_938 + V_934 | 2 | 0.000 | 2 |
| V_894 | + (0.095)V_1138 - (1.079)V_956 + V_894 | 2 | 0.007 | 2 |
| V_932 | + (1.11e-03)V_1138 + (0.029)V_956 - (1.032)V_934 + V_932 | 2 | 0.000 | 1 |
| V_920 | + (9.01e-03)V_1138 - (0.021)V_956 - (0.985)V_922 + V_920 | 2 | 0.000 | 1 |
| V_944 | - (0.034)V_1138 + (4.037)V_956 - (5.003)V_954 + V_944 | 2 | 0.000 | 0 |
| V_922 | + (0.045)V_1138 - (3.556)V_956 + (4.472)V_954 - (2.238)V_944 + (9.164)V_934 - (8.878)V_932 + V_922 | 2 | 0.000 | 0 |
| V_952 | - (3.96e-03)V_1138 + (0.945)V_956 - (1.941)V_954 + V_952 | 2 | 0.000 | -1 |
| V_950 | + (7.85e-05)V_1138 - (0.725)V_956 + (2.421)V_954 - (2.695)V_952 + V_950 | 2 | 0.000 | -1 |
| V_812 | - (0.688)V_1138 + V_812 | 3 | 0.051 | 20 |
| V_810 | + (2.65e-03)V_1138 - (1.003)V_812 + V_810 | 3 | 0.000 | 6 |
| V_840 | + (0.072)V_1138 + V_840 - (1.106)V_812 | 3 | 0.006 | 3 |
| V_808 | + (3.30e-04)V_1138 + (0.909)V_812 - (1.909)V_810 + V_808 | 3 | 0.000 | 2 |
| V_836 | + (0.012)V_1138 + V_836 - (1.291)V_830 + (0.272)V_812 | 3 | 0.000 | 0 |
| V_830 | + (2.40e-03)V_1138 - (0.649)V_840 + (1.296)V_836 - (0.673)V_830 + (0.024)V_812 | 3 | 0.000 | 0 |
| V_824 | - (0.012)V_1138 - (0.369)V_840 + V_824 - (0.611)V_812 | 3 | 0.000 | 0 |
| V_826 | + (4.55e-03)V_1138 + V_826 - (1.184)V_824 + (0.178)V_812 | 3 | 0.000 | -1 |
| V_806 | - (1.03e-04)V_1138 - (1.064)V_812 + (3.115)V_810 - (3.051)V_808 + V_806 | 3 | 0.000 | -1 |
| V_844 | + (6.76e-05)V_1138 + V_844 - (1.100)V_840 + (0.094)V_812 | 4 | 0.000 | 18 |
| V_870 | - (6.85e-03)V_1138 + V_870 - (1.027)V_844 | 4 | 0.002 | 3 |
| V_852 | - (1.92e-03)V_1138 + V_852 - (1.014)V_844 | 4 | 0.000 | 3 |
| V_858 | + (2.22e-03)V_1138 + V_858 - (3.861)V_854 + (3.104)V_852 - (0.246)V_844 | 4 | 0.000 | 2 |
| V_882 | + (4.10e-03)V_1138 + V_882 - (1.066)V_880 + (0.066)V_844 | 4 | 0.000 | 1 |
| V_880 | - (0.022)V_1138 + (1.652)V_972 - (1.639)V_970 + V_880 - (1.292)V_870 + (0.309)V_844 | 4 | 0.000 | 1 |
| V_854 | - (2.59e-04)V_1138 + V_854 - (1.200)V_852 + (0.200)V_844 | 4 | 0.000 | 1 |
| V_876 | + (4.01e-03)V_1138 + V_876 - (4.539)V_870 + (3.596)V_868 - (0.057)V_844 | 4 | 0.000 | -1 |
| V_868 | + (1.12e-03)V_1138 - (0.936)V_870 + V_868 - (0.068)V_844 | 4 | 0.000 | -1 |
| V_1226 | + V_1226 - (11.356)V_1222 + (28.656)V_1220 - (32.922)V_1218 + (19.381)V_1216 - (4.762)V_1214 + (2.35e-03)V_1138 | 5 | 0.000 | 14 |
| V_1228 | + V_1228 - (1.042)V_1226 + (0.029)V_1138 | 5 | 0.000 | 5 |
| V_1270 | + V_1270 - (1.074)V_1226 + (0.067)V_1138 | 5 | 0.005 | 4 |
| V_1274 | + V_1274 - (1.018)V_1270 + (0.023)V_1226 + (9.05e-04)V_1138 | 5 | 0.000 | 2 |
| V_1230 | + V_1230 - (1.952)V_1228 + (0.951)V_1226 + (6.85e-04)V_1138 | 5 | 0.000 | 1 |
| V_1268 | + (0.534)V_1274 - (1.532)V_1270 + V_1268 - (5.81e-03)V_1226 + (2.52e-03)V_1138 | 5 | 0.000 | 0 |
| V_1252 | - (0.977)V_1256 + V_1252 - (0.066)V_1226 + (0.029)V_1138 | 5 | 0.000 | 0 |
| V_1232 | + V_1232 - (2.732)V_1230 + (2.493)V_1228 - (0.760)V_1226 + (1.50e-04)V_1138 | 5 | 0.000 | -1 |
| V_972 | - (0.328)V_1138 - (0.722)V_1016 + (9.839)V_1012 - (9.895)V_1010 + (10.100)V_984 - (9.999)V_982 + V_972 | 6 | 0.002 | 7 |
| V_970 | + (0.017)V_1138 - (1.008)V_972 + V_970 | 6 | 0.000 | 4 |
| V_968 | + (1.18e-03)V_1138 + (0.919)V_972 - (1.920)V_970 + V_968 | 6 | 0.000 | 1 |
| V_1018 | - (0.044)V_1138 + V_1018 - (1.035)V_1016 + (0.080)V_972 | 6 | 0.000 | -1 |
| V_962 | - (1.26e-03)V_1138 + (2.102)V_972 - (8.636)V_970 + (12.970)V_968 - (7.436)V_966 + V_962 | 6 | 0.000 | -1 |
| V_1184 | + V_1184 - (0.786)V_1138 | 7 | 0.023 | 10 |
par(op)
if (!largeSet)
{
cormat <- cor(DEdataframe[,varlistc],method="pearson")
cormat[is.na(cormat)] <- 0
gplots::heatmap.2(abs(cormat),
trace = "none",
mar = c(5,5),
col=rev(heat.colors(5)),
main = "Correlation after ILAA",
cexRow = cexheat,
cexCol = cexheat,
srtCol=45,
srtRow=45,
key.title=NA,
key.xlab="|Pearson Correlation|",
xlab="Feature", ylab="Feature")
par(op)
diag(cormat) <- 0
print(max(abs(cormat)))
}
[1]
0.7992318
classes <- unique(dataframe[1:numsub,outcome])
raincolors <- rainbow(length(classes))
names(raincolors) <- classes
topvars <- univariate_BinEnsemble(dataframe,outcome)
lso <- LASSO_MIN(formula(paste(outcome,"~.")),dataframe,family="binomial")
topvars <- unique(c(names(topvars),lso$selectedfeatures))
pander::pander(head(topvars))
V_1300, V_1260, V_1246, V_1204, V_1202 and V_1174
# names(topvars)
#if (nrow(dataframe) < 1000)
#{
datasetframe.umap = umap(scale(dataframe[1:numsub,topvars]),n_components=2)
# datasetframe.umap = umap(dataframe[1:numsub,varlist],n_components=2)
plot(datasetframe.umap$layout,xlab="U1",ylab="U2",main="UMAP: Original",t='n')
text(datasetframe.umap$layout,labels=dataframe[1:numsub,outcome],col=raincolors[dataframe[1:numsub,outcome]+1])
#}
varlistcV <- names(varratio[varratio >= 0.01])
topvars <- univariate_BinEnsemble(DEdataframe[,varlistcV],outcome)
lso <- LASSO_MIN(formula(paste(outcome,"~.")),DEdataframe[,varlistcV],family="binomial")
topvars <- unique(c(names(topvars),lso$selectedfeatures))
pander::pander(head(topvars))
La_V_984, La_V_956, La_V_1002, La_V_1068 and La_V_1282
varlistcV <- varlistcV[varlistcV != outcome]
# DEdataframe[,outcome] <- as.numeric(DEdataframe[,outcome])
#if (nrow(dataframe) < 1000)
#{
datasetframe.umap = umap(scale(DEdataframe[1:numsub,topvars]),n_components=2)
# datasetframe.umap = umap(DEdataframe[1:numsub,varlistcV],n_components=2)
plot(datasetframe.umap$layout,xlab="U1",ylab="U2",main="UMAP: After ILAA",t='n')
text(datasetframe.umap$layout,labels=DEdataframe[1:numsub,outcome],col=raincolors[DEdataframe[1:numsub,outcome]+1])
#}
univarRAW <- uniRankVar(varlist,
paste(outcome,"~1"),
outcome,
dataframe,
rankingTest="AUC")
100 : V_1064 200 : V_854
univarDe <- uniRankVar(varlistc,
paste(outcome,"~1"),
outcome,
DEdataframe,
rankingTest="AUC",
)
100 : La_V_1064 200 : La_V_854
univariate_columns <- c("caseMean","caseStd","controlMean","controlStd","controlKSP","ROCAUC")
##top variables
topvar <- c(1:length(varlist)) <= TopVariables
tableRaw <- univarRAW$orderframe[topvar,univariate_columns]
pander::pander(tableRaw)
| caseMean | caseStd | controlMean | controlStd | controlKSP | ROCAUC | |
|---|---|---|---|---|---|---|
| V_908 | 0.221 | 0.128 | 0.261 | 0.117 | 0.579 | 0.596 |
| V_906 | 0.220 | 0.127 | 0.261 | 0.117 | 0.585 | 0.596 |
| V_904 | 0.220 | 0.127 | 0.261 | 0.117 | 0.592 | 0.596 |
| V_892 | 0.219 | 0.127 | 0.261 | 0.121 | 0.626 | 0.596 |
| V_890 | 0.219 | 0.127 | 0.261 | 0.121 | 0.616 | 0.596 |
| V_888 | 0.219 | 0.127 | 0.261 | 0.122 | 0.603 | 0.596 |
| V_912 | 0.223 | 0.129 | 0.263 | 0.117 | 0.604 | 0.595 |
| V_910 | 0.222 | 0.128 | 0.262 | 0.117 | 0.587 | 0.595 |
| V_896 | 0.220 | 0.127 | 0.261 | 0.120 | 0.620 | 0.595 |
| V_894 | 0.219 | 0.127 | 0.261 | 0.121 | 0.625 | 0.595 |
topLAvar <- univarDe$orderframe$Name[str_detect(univarDe$orderframe$Name,"La_")]
topLAvar <- unique(c(univarDe$orderframe$Name[topvar],topLAvar[1:as.integer(TopVariables/2)]))
finalTable <- univarDe$orderframe[topLAvar,univariate_columns]
pander::pander(finalTable)
| caseMean | caseStd | controlMean | controlStd | controlKSP | ROCAUC | |
|---|---|---|---|---|---|---|
| La_V_1200 | -2.21e-05 | 1.11e-04 | -1.44e-04 | 1.45e-04 | 0.694 | 0.776 |
| La_V_1210 | -1.03e-04 | 2.19e-04 | -3.72e-04 | 3.62e-04 | 0.618 | 0.775 |
| La_V_1216 | -6.36e-04 | 1.26e-03 | -1.73e-03 | 1.13e-03 | 0.814 | 0.774 |
| La_V_992 | -1.82e-04 | 1.06e-03 | -7.60e-04 | 7.93e-04 | 0.052 | 0.759 |
| La_V_1004 | -2.06e-04 | 2.11e-03 | -1.62e-03 | 1.69e-03 | 0.108 | 0.756 |
| La_V_1274 | 6.12e-04 | 8.38e-04 | 1.33e-03 | 9.44e-04 | 0.130 | 0.749 |
| La_V_886 | -9.64e-06 | 3.19e-05 | 2.09e-05 | 5.89e-05 | 0.510 | 0.743 |
| La_V_890 | 1.12e-04 | 8.46e-04 | 6.94e-04 | 5.50e-04 | 0.828 | 0.741 |
| La_V_840 | 3.51e-03 | 9.94e-03 | 1.11e-02 | 6.82e-03 | 0.786 | 0.738 |
| La_V_984 | -8.54e-03 | 3.09e-02 | 1.28e-02 | 1.54e-02 | 0.423 | 0.729 |
dc <- getLatentCoefficients(DEdataframe)
fscores <- attr(DEdataframe,"fscore")
pander::pander(c(mean=mean(sapply(dc,length)),total=length(dc),fraction=length(dc)/(ncol(dataframe)-1)))
| mean | total | fraction |
|---|---|---|
| 5.16 | 223 | 0.996 |
theCharformulas <- attr(dc,"LatentCharFormulas")
topvar <- rownames(tableRaw)
finalTable <- rbind(finalTable,tableRaw[topvar[!(topvar %in% topLAvar)],univariate_columns])
orgnamez <- rownames(finalTable)
orgnamez <- str_remove_all(orgnamez,"La_")
finalTable$RAWAUC <- univarRAW$orderframe[orgnamez,"ROCAUC"]
finalTable$DecorFormula <- theCharformulas[rownames(finalTable)]
finalTable$fscores <- fscores[rownames(finalTable)]
finalTable$varratio <- varratio[rownames(finalTable)]
Final_Columns <- c("DecorFormula","caseMean","caseStd","controlMean","controlStd","controlKSP","ROCAUC","RAWAUC","fscores","varratio")
finalTable <- finalTable[order(-finalTable$ROCAUC),]
pander::pander(finalTable[,Final_Columns])
| DecorFormula | caseMean | caseStd | controlMean | controlStd | controlKSP | ROCAUC | RAWAUC | fscores | varratio | |
|---|---|---|---|---|---|---|---|---|---|---|
| La_V_1200 | + V_1200 - (1.980)V_1198 + (0.981)V_1196 - (2.06e-03)V_1138 | -2.21e-05 | 1.11e-04 | -1.44e-04 | 1.45e-04 | 0.694 | 0.776 | 0.566 | 1 | 1.04e-06 |
| La_V_1210 | + V_1210 - (5.772)V_1208 + (8.145)V_1206 - (8.142)V_1202 + (8.175)V_1200 - (5.145)V_1198 + (1.738)V_1196 - (2.07e-03)V_1138 | -1.03e-04 | 2.19e-04 | -3.72e-04 | 3.62e-04 | 0.618 | 0.775 | 0.557 | -6 | 5.03e-06 |
| La_V_1216 | + V_1216 - (1.023)V_1214 + (0.013)V_1138 | -6.36e-04 | 1.26e-03 | -1.73e-03 | 1.13e-03 | 0.814 | 0.774 | 0.555 | 3 | 7.81e-05 |
| La_V_992 | - (1.48e-03)V_1138 + (0.829)V_1004 - (0.808)V_1002 - (1.020)V_994 + V_992 | -1.82e-04 | 1.06e-03 | -7.60e-04 | 7.93e-04 | 0.052 | 0.759 | 0.580 | 1 | 4.10e-05 |
| La_V_1004 | - (0.026)V_1138 + V_1004 - (0.975)V_1002 | -2.06e-04 | 2.11e-03 | -1.62e-03 | 1.69e-03 | 0.108 | 0.756 | 0.571 | 7 | 1.71e-04 |
| La_V_1274 | + V_1274 - (1.018)V_1270 + (0.023)V_1226 + (9.05e-04)V_1138 | 6.12e-04 | 8.38e-04 | 1.33e-03 | 9.44e-04 | 0.130 | 0.749 | 0.544 | 2 | 3.74e-05 |
| La_V_886 | - (2.30e-04)V_1138 + V_886 - (2.885)V_884 + (2.767)V_882 - (0.881)V_880 - (1.38e-03)V_844 | -9.64e-06 | 3.19e-05 | 2.09e-05 | 5.89e-05 | 0.510 | 0.743 | 0.595 | -4 | 1.54e-07 |
| La_V_890 | + (3.26e-03)V_1138 + V_890 - (4.805)V_882 + (3.799)V_880 - (3.28e-03)V_844 | 1.12e-04 | 8.46e-04 | 6.94e-04 | 5.50e-04 | 0.828 | 0.741 | 0.596 | -4 | 3.77e-05 |
| La_V_840 | + (0.072)V_1138 + V_840 - (1.106)V_812 | 3.51e-03 | 9.94e-03 | 1.11e-02 | 6.82e-03 | 0.786 | 0.738 | 0.589 | 3 | 5.71e-03 |
| La_V_984 | - (0.856)V_1138 + V_984 | -8.54e-03 | 3.09e-02 | 1.28e-02 | 1.54e-02 | 0.423 | 0.729 | 0.582 | 3 | 3.14e-02 |
| V_908 | NA | 2.21e-01 | 1.28e-01 | 2.61e-01 | 1.17e-01 | 0.579 | 0.596 | 0.596 | NA | NA |
| V_906 | NA | 2.20e-01 | 1.27e-01 | 2.61e-01 | 1.17e-01 | 0.585 | 0.596 | 0.596 | NA | NA |
| V_904 | NA | 2.20e-01 | 1.27e-01 | 2.61e-01 | 1.17e-01 | 0.592 | 0.596 | 0.596 | NA | NA |
| V_892 | NA | 2.19e-01 | 1.27e-01 | 2.61e-01 | 1.21e-01 | 0.626 | 0.596 | 0.596 | NA | NA |
| V_890 | NA | 2.19e-01 | 1.27e-01 | 2.61e-01 | 1.21e-01 | 0.616 | 0.596 | 0.596 | NA | NA |
| V_888 | NA | 2.19e-01 | 1.27e-01 | 2.61e-01 | 1.22e-01 | 0.603 | 0.596 | 0.596 | NA | NA |
| V_912 | NA | 2.23e-01 | 1.29e-01 | 2.63e-01 | 1.17e-01 | 0.604 | 0.595 | 0.595 | NA | NA |
| V_910 | NA | 2.22e-01 | 1.28e-01 | 2.62e-01 | 1.17e-01 | 0.587 | 0.595 | 0.595 | NA | NA |
| V_896 | NA | 2.20e-01 | 1.27e-01 | 2.61e-01 | 1.20e-01 | 0.620 | 0.595 | 0.595 | NA | NA |
| V_894 | NA | 2.19e-01 | 1.27e-01 | 2.61e-01 | 1.21e-01 | 0.625 | 0.595 | 0.595 | NA | NA |
featuresnames <- colnames(dataframe)[colnames(dataframe) != outcome]
pc <- prcomp(dataframe[,iscontinous],center = TRUE,scale. = TRUE,tol=0.01) #principal components
predPCA <- predict(pc,dataframe[,iscontinous])
PCAdataframe <- as.data.frame(cbind(predPCA,dataframe[,!iscontinous]))
colnames(PCAdataframe) <- c(colnames(predPCA),colnames(dataframe)[!iscontinous])
#plot(PCAdataframe[,colnames(PCAdataframe)!=outcome],col=dataframe[,outcome],cex=0.65,cex.lab=0.5,cex.axis=0.75,cex.sub=0.5,cex.main=0.75)
#pander::pander(pc$rotation)
PCACor <- cor(PCAdataframe[,colnames(PCAdataframe) != outcome])
gplots::heatmap.2(abs(PCACor),
trace = "none",
# scale = "row",
mar = c(5,5),
col=rev(heat.colors(5)),
main = "PCA Correlation",
cexRow = 0.5,
cexCol = 0.5,
srtCol=45,
srtRow= -45,
key.title=NA,
key.xlab="Pearson Correlation",
xlab="Feature", ylab="Feature")
EFAdataframe <- dataframeScaled
if (length(iscontinous) < 2000)
{
topred <- min(length(iscontinous),nrow(dataframeScaled),ncol(predPCA)-1)
if (topred < 2) topred <- 2
uls <- fa(dataframeScaled[,iscontinous],nfactors=topred,rotate="varimax",warnings=FALSE) # EFA analysis
predEFA <- predict(uls,dataframeScaled[,iscontinous])
EFAdataframe <- as.data.frame(cbind(predEFA,dataframeScaled[,!iscontinous]))
colnames(EFAdataframe) <- c(colnames(predEFA),colnames(dataframeScaled)[!iscontinous])
EFACor <- cor(EFAdataframe[,colnames(EFAdataframe) != outcome])
gplots::heatmap.2(abs(EFACor),
trace = "none",
# scale = "row",
mar = c(5,5),
col=rev(heat.colors(5)),
main = "EFA Correlation",
cexRow = 0.5,
cexCol = 0.5,
srtCol=45,
srtRow= -45,
key.title=NA,
key.xlab="Pearson Correlation",
xlab="Feature", ylab="Feature")
}
par(op)
par(xpd = TRUE)
dataframe[,outcome] <- factor(dataframe[,outcome])
rawmodel <- rpart(paste(outcome,"~."),dataframe,control=rpart.control(maxdepth=3))
pr <- predict(rawmodel,dataframe,type = "class")
ptab <- list(er="Error",detail=matrix(nrow=6,ncol=1))
if (length(unique(pr))>1)
{
plot(rawmodel,main="Raw",branch=0.5,uniform = TRUE,compress = TRUE,margin=0.1)
text(rawmodel, use.n = TRUE,cex=0.75)
ptab <- epiR::epi.tests(table(pr==0,dataframe[,outcome]==0))
}
pander::pander(table(dataframe[,outcome],pr))
| 0 | 1 | |
|---|---|---|
| 0 | 30 | 0 |
| 1 | 17 | 14 |
pander::pander(ptab$detail[c(5,3,4,6),])
| statistic | est | lower | upper | |
|---|---|---|---|---|
| 5 | diag.ac | 0.721 | 0.592 | 0.829 |
| 3 | se | 0.452 | 0.273 | 0.640 |
| 4 | sp | 1.000 | 0.884 | 1.000 |
| 6 | diag.or | Inf | NA | Inf |
par(op)
par(xpd = TRUE)
DEdataframe[,outcome] <- factor(DEdataframe[,outcome])
IDeAmodel <- rpart(paste(outcome,"~."),DEdataframe[,c(outcome,varlistcV)],control=rpart.control(maxdepth=3))
pr <- predict(IDeAmodel,DEdataframe,type = "class")
ptab <- list(er="Error",detail=matrix(nrow=6,ncol=1))
if (length(unique(pr))>1)
{
plot(IDeAmodel,main="ILAA",branch=0.5,uniform = TRUE,compress = TRUE,margin=0.1)
text(IDeAmodel, use.n = TRUE,cex=0.75)
ptab <- epiR::epi.tests(table(pr==0,DEdataframe[,outcome]==0))
}
pander::pander(table(DEdataframe[,outcome],pr))
| 0 | 1 | |
|---|---|---|
| 0 | 25 | 5 |
| 1 | 8 | 23 |
pander::pander(ptab$detail[c(5,3,4,6),])
| statistic | est | lower | upper | |
|---|---|---|---|---|
| 5 | diag.ac | 0.787 | 0.663 | 0.881 |
| 3 | se | 0.742 | 0.554 | 0.881 |
| 4 | sp | 0.833 | 0.653 | 0.944 |
| 6 | diag.or | 14.375 | 4.108 | 50.307 |
par(op)
par(xpd = TRUE)
PCAdataframe[,outcome] <- factor(PCAdataframe[,outcome])
PCAmodel <- rpart(paste(outcome,"~."),PCAdataframe,control=rpart.control(maxdepth=3))
pr <- predict(PCAmodel,PCAdataframe,type = "class")
ptab <- list(er="Error",detail=matrix(nrow=6,ncol=1))
if (length(unique(pr))>1)
{
plot(PCAmodel,main="PCA",branch=0.5,uniform = TRUE,compress = TRUE,margin=0.1)
text(PCAmodel, use.n = TRUE,cex=0.75)
ptab <- epiR::epi.tests(table(pr==0,PCAdataframe[,outcome]==0))
}
pander::pander(table(PCAdataframe[,outcome],pr))
| 0 | 1 | |
|---|---|---|
| 0 | 22 | 8 |
| 1 | 4 | 27 |
pander::pander(ptab$detail[c(5,3,4,6),])
| statistic | est | lower | upper | |
|---|---|---|---|---|
| 5 | diag.ac | 0.803 | 0.682 | 0.894 |
| 3 | se | 0.871 | 0.702 | 0.964 |
| 4 | sp | 0.733 | 0.541 | 0.877 |
| 6 | diag.or | 18.562 | 4.931 | 69.883 |
par(op)
EFAdataframe[,outcome] <- factor(EFAdataframe[,outcome])
EFAmodel <- rpart(paste(outcome,"~."),EFAdataframe,control=rpart.control(maxdepth=3))
pr <- predict(EFAmodel,EFAdataframe,type = "class")
ptab <- list(er="Error",detail=matrix(nrow=6,ncol=1))
if (length(unique(pr))>1)
{
plot(EFAmodel,main="EFA",branch=0.5,uniform = TRUE,compress = TRUE,margin=0.1)
text(EFAmodel, use.n = TRUE,cex=0.75)
ptab <- epiR::epi.tests(table(pr==0,EFAdataframe[,outcome]==0))
}
pander::pander(table(EFAdataframe[,outcome],pr))
| 0 | 1 | |
|---|---|---|
| 0 | 25 | 5 |
| 1 | 4 | 27 |
pander::pander(ptab$detail[c(5,3,4,6),])
| statistic | est | lower | upper | |
|---|---|---|---|---|
| 5 | diag.ac | 0.852 | 0.738 | 0.930 |
| 3 | se | 0.871 | 0.702 | 0.964 |
| 4 | sp | 0.833 | 0.653 | 0.944 |
| 6 | diag.or | 33.750 | 8.134 | 140.031 |
par(op)